var nodemailer = require('nodemailer')
var smtpTransport = require('nodemailer-smtp-transport');
var schedule = require('node-schedule');
var config = {
       //邮件配置
    email: {
        service: 'QQ',
        user: '1070156025@qq.com',
        pass: 'hgpkasprvlinbcbi',
    }
}
smtpTransport = nodemailer.createTransport(smtpTransport({
    service: config.email.service,
    auth: {
        user: config.email.user,
        pass: config.email.pass
    }
}));

/**
 * @param {String} recipient 收件人
 * @param {String} subject 发送的主题
 * @param {String} html 发送的html内容
 */
var sendMail = function (recipient, subject, html) {

    smtpTransport.sendMail({

        from: config.email.user,
        to: recipient,
        subject: subject,
        html: html

    }, function (error, response) {
        if (error) {
            console.log(error);
        }
        console.log('发送成功')
    });
}



function scheduleCancel(){

    var counter = 1;
    var j = schedule.scheduleJob('0 0 0 * * *', function(){
        
        console.log('定时器触发次数：' + counter);
        counter++;
        sendMail('2259785294@qq.com','娇娇我爱你', '娇娇我爱你');
        
    });

    // setTimeout(function() {
    //     console.log('定时器取消')
    //     j.cancel();   
    // }, 200000);
    
}

scheduleCancel()
